package com.gomore.opple.module.award.adapter;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.clock.scratch.ScratchView;
import com.gomore.opple.R;
import com.gomore.opple.common.GlobalConstant;
import com.gomore.opple.module.IntentStart;
import com.gomore.opple.rest.jdecard.GroupByOrderNumber;
import com.gomore.opple.rest.lottery.RsAwardDraw;
import com.gomore.opple.service.DrawAwardClickListener;
import com.gomore.opple.service.UseJDEClicklistener;
import com.gomore.opple.utils.DateUtil;
import com.gomore.opple.utils.DensityUtil;
import com.gomore.opple.utils.DialogUtils;
import com.gomore.opple.utils.GlideImageLoader;
import com.gomore.opple.web.cgform.jdecard.entity.TOJingdongEcardEntity;
import com.gomore.opple.widgets.adapter.CommonAdapter;
import com.gomore.opple.widgets.adapter.ViewHolder;
import com.gomore.opple.widgets.dialog.ConfirmDialog;
import com.youth.banner.Banner;
import com.youth.banner.BannerConfig;
import com.youth.banner.Transformer;
import com.youth.banner.listener.OnBannerClickListener;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by asus on 2017/5/26.
 */
public class AwardAdapter extends CommonAdapter<RsAwardDraw> {
    Activity mactivity;
    Context mContext;
    String mState;
    RsAwardDraw mrsAwardDraw;
    private DrawAwardClickListener mdrawAwardClickListener;

    public void setDrawAwardClickListener(DrawAwardClickListener drawAwardClickListener) {
        mdrawAwardClickListener = drawAwardClickListener;
    }

    public AwardAdapter(Activity activity, Context context, int layoutId, List<RsAwardDraw> messageList, String state) {
        super(context, layoutId, messageList);
        mactivity = activity;
        mContext = context;
        mState = state;
    }

    @Override
    protected void convert(ViewHolder holder, final RsAwardDraw rsAwardDraw, final int position) {
        mrsAwardDraw = rsAwardDraw;
        LinearLayout unlottery_linearlayout = holder.getView(R.id.unlottery_linearlayout);
        LinearLayout lotteried_linearlayout = holder.getView(R.id.lotteried_linearlayout);
        //未抽奖
        TextView unlottery_orderNumber = holder.getView(R.id.unlottery_orderNumber);
        TextView unlottery_go_award = holder.getView(R.id.unlottery_go_award);
        //已抽奖
        TextView lotteried_orderNumber = holder.getView(R.id.lotteried_orderNumber);
        TextView award_time = holder.getView(R.id.award_time);
        TextView lotteried_description = holder.getView(R.id.lotteried_description);
        if (mState.equals(GlobalConstant.AwardState.INITIAL)) {
            unlottery_linearlayout.setVisibility(View.VISIBLE);
            lotteried_linearlayout.setVisibility(View.GONE);
            if (rsAwardDraw.getDraw() != null && rsAwardDraw.getDraw().getOrderNumber() != null) {
                unlottery_orderNumber.setText(rsAwardDraw.getDraw().getOrderNumber());
            }
        } else {
            unlottery_linearlayout.setVisibility(View.GONE);
            lotteried_linearlayout.setVisibility(View.VISIBLE);
            if (rsAwardDraw.getDraw() != null) {
                if (rsAwardDraw.getDraw().getOrderNumber() != null) {
                    lotteried_orderNumber.setText(rsAwardDraw.getDraw().getOrderNumber());
                }
                if (rsAwardDraw.getDraw().getDrawDate() != null) {
                    award_time.setText(DateUtil.fomatforDate(rsAwardDraw.getDraw().getDrawDate(), DateUtil.DATE_FORMATTER_1));
                }
                if (rsAwardDraw.getDraw().getAwardDescription() != null) {
                    lotteried_description.setText(rsAwardDraw.getDraw().getAwardDescription());
                }
            }
        }

        unlottery_go_award.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //确定框
                ConfirmDialog.onNoOnclickListener onNoOnclickListener = null;
                ConfirmDialog.onYesOnclickListener onYesOnclickListener = null;
                final String title = "提示";
                String message = "确定去抽奖吗?";
                onYesOnclickListener = new ConfirmDialog.onYesOnclickListener() {
                    @Override
                    public void onYesClick() {
                        mdrawAwardClickListener.drawAward(rsAwardDraw.getDraw());
                    }
                };
                onNoOnclickListener = new ConfirmDialog.onNoOnclickListener() {
                    @Override
                    public void onNoClick() {
                        DialogUtils.cancel();
                    }
                };
                DialogUtils.showConfirmDialog(mactivity, onYesOnclickListener, onNoOnclickListener, title, message);
            }
        });
    }
}
